<?php
namespace bankworking\client;

class Client {
	
	private $name;
	private $address;
	private $theCash;		//the cash
	private $salary;
	private $deposit = array();
	private $credit = array();
	
	
	public function __construct($name, $address, $theCash, $salary){
	
		$this->setName($name);
		$this->setAddress($address);
		$this->setTheCash($theCash);
		$this->setSalary($salary);
		//$this->deposit = $deposit;
		//$this->credit = $credit;
	
	}
	
	public function setName($newName){
		try {
			if ($newName == "" || $newName == null){
				throw new Exception("Please, enter client name!");
			} else if (is_numeric($newName)) {
				throw new Exception("Client name not be only numbers!");
			} else {
				$this->name = $newName;
				return true;
			}
		} catch (Exception $e) {
			echo "<p>" . $e->getMessage() . "</p>";
		}
	
	}
	
	public function getName(){
		return $this->name;
	}
	
	public function setAddress($newAddress){
		try {
			if ($newAddress == "" || $newAddress == null){
				throw new Exception("Please, enter address!");
			} else if (is_numeric($newAddress)) {
				throw new Exception("Address not be only numbers!");
			} else {
				$this->address = $newAddress;
				return true;
			}
		} catch (Exception $e) {
			echo "<p>" . $e->getMessage() . "</p>";
		}
	}
	
	public function getAddress(){
		return $this->address;
	}
	
	public function setTheCash($money){
		try {
			if ($money == "" || $money == null){
				throw new Exception("Please, enter some money the cash!");
			} else if (!is_numeric($money)) {
				throw new Exception("Please, enter only numbers!");
			} else {
				$this->theCash = $money;
				return true;
			}
		} catch (Exception $e) {
			echo "<p>" . $e->getMessage() . "</p>";
		}
	}
	
	public function getTheCash(){
		return $this->moneyInASafe;
	}
	
	public function setSalary($newSalary){
		try {
			if ($newSalary == "" || $newSalary == null){
				throw new Exception("Please, enter Salary!");
			} else if (!is_numeric($newSalary)) {
				throw new Exception("Please, enter only numbers for salary!");
			} else {
				$this->salary = $newSalary;
				return true;
			}
		} catch (Exception $e) {
			echo "<p>" . $e->getMessage() . "</p>";
		}
	}
	
	public function getSalary(){
		return $this->salary;
	}
	
	public function addDeposit(Deposit $deposit){
		$name = $deposit->getName();
		$this->deposit[$name] = $deposit;
	}
	
	public function addCredit(Credit $credit){
		$name = $credit->getName();
		$this->deposit[$name] = $deposit;
	}
	
	public function showClientInfo(){
		echo "--------------Client Info----------------------<br />";
		echo "Name: ". $this->name ."<br />";
		echo "Address: ". $this->address ."<br />";
		echo "The Cash: ". $this->theCash ."<br />";
		echo "Salary: ". $this->salary ."<br />";
		//echo "Deposit: ". $this->deposit ."<br />";
		//echo "Credit: ". $this->credit ."<br />";
	
		echo "---------------End------------------------------<br />";
	}
	
}